package com.lanou.myim.model;

import com.easemob.chat.EMChatManager;
import com.easemob.chat.EMContactManager;
import com.easemob.exceptions.EaseMobException;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dllo on 16/3/11.
 */
public class AddFriendsModel implements AddFriendsModelInterface{
    @Override
    public void addFriend(String userName, String reason) {
        try {
            EMContactManager.getInstance().addContact(userName, reason);
        } catch (EaseMobException e) {
            e.printStackTrace();
        }
    }

    @Override
    public boolean isRepeat(String username) {
        List<String> userNames = null;
        try {
            userNames = EMChatManager.getInstance().getContactUserNames();
        } catch (EaseMobException e) {
            e.printStackTrace();
        }
        boolean repeat = false;
        for (String name : userNames){
            if (name.equals(username)){
                repeat = true;
            }
        }
        return repeat;
    }
}
